package com.toughsoftware.pins.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.toughsoftware.pins.R;
import com.toughsoftware.pins.adapter.AdptrPinBean;
import com.toughsoftware.pins.data.bean.BnPin;
import com.toughsoftware.pins.listener.LstnrPinItem;

public class FrgPinList extends Fragment {
	
	private ListView lstListado;
	
	private LstnrPinItem listener;
	
	@Override
	public View onCreateView(LayoutInflater inflater, 
			                 ViewGroup container, 
			                 Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		return inflater.inflate(R.layout.frg_pin_list, container, false);
	}
	
	@Override
	public void onActivityCreated(Bundle state) {
		super.onActivityCreated(state);
		
		lstListado = (ListView)getView().findViewById(R.id.lvPinList);
		
		lstListado.setAdapter(new AdptrPinBean(this));
		
		lstListado.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> list, View view, int pos, long id) {
				if (listener!=null) {
					listener.onSelectedPinItem(
							(BnPin)lstListado.getAdapter().getItem(pos));
				}
			}
		});
	}
	
	public void setLstnrPinItem(LstnrPinItem listener) {
		this.listener=listener;
	}
}
